// jscs:disable

export const WindManUtils = {
    formatNum: function(num) {
        if (num < 1000) {
            return num;
        }
        if (num >= 1000 && num < 10000) {
            return Math.round(num / 1000) + '千';
        }
        if (num >= 10000) {
            return Math.round(num / 10000) + '万';
        }
    },
    
    changeChapterStr:function(str) {
        return str && str.replace('章', '章 ');
    },

    setStorage: function(key, json){
        try{
            localStorage.setItem(key, JSON.stringify(json));
        }catch(err){
            console.log(err.message);
        }
    },

    getStorage: function(key){
        const json = localStorage.getItem(key);
        if(typeof json == 'string' && json !== undefined && json !== 'undefined') {
            try{
                const data = JSON.parse(json);
                return data;
            }catch(err){
                console.log(err);
                return false;
            }
        }
    },

    removeStorage: function(key){
        localStorage.removeItem(key);
    },

    removeAllStorage: function(){
        localStorage.clear();
    }
}